Part of the course requirements are to be able to interpret flowcharts. You should be able to identify examples of programming structures and other programming theory as well as be able to describe the purpose of algorithms.
Examine the flowcharts below and answer the questions alongside them.
Question 1
a) Explain the purpose of this algorithm.
The program counts how many consecutive digits starting from 1 need to be added to reach a total greater than 500. In this case the answer is 33 i.e. if you add 1 + 2 + 3 + ... + 32 + 33 > 500.
b) State a variable used in this program.
n and total are the two variables used in this program.
c) Is this an example of selection or iteration?
While the diamond selection flowchart symbol is used this is as the condition check of a loop. This is an example of iteration.
Question 2
a) Explain the purpose of this algorithm.
The program outputs all the multiples of 5 between a number entered by the user and 50 inclusive.
b) Give an example of selection used in this program.
Selection is used to check if the current number is evenly divisible by 5 where it says Number % 5 = 0? and the number s only output if this is true.
c) Describe how iteration is used in this program.
The program loops through each number between the number entered by the user and 50 inclusive.
Question 3
a) Explain the purpose of this algorithm.
The program accepts 3 values from the user and adds them together. If the result is greater than 100 it outputs Well done and the total. If the total is 50 or any number up to but not including 100 it outputs Not bad and the total and in all other circumstances it outputs Bad luck and the total.
b) Is there an example of selection or iteration in this program?
Selection is used to check the total and give an appropriate response. There is no place where a part of the algorithm repeats. This is an example of selection.
c) What programming structure might be used to implement this.
An if else statement with an else if condition would be appropriate to code this .